package com.hellobike.haxing.modules.order.send;

import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.client.producer.SendCallback;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 交易关闭发送C端Mq返回库存
 */
@Component
@Data
@Slf4j
public class OrderCloseCSend {
    @Autowired
    private RocketMQTemplate rocketMQTemplate;

    /**
     * 订单关闭后向C端发送返回库存
     * @param orderId
     */
    public void sendOrderClose(Long orderId) {
        rocketMQTemplate.asyncSend("close-order-backend-stock-topic", orderId, new SendCallback() {
            @Override
            public void onSuccess(SendResult sendResult) {
                log.info("==close-order-backend-stock-topic=success===orderId=>{}",orderId);
            }

            @Override
            public void onException(Throwable e) {
                log.error("==close-order-backend-stock-topic= error==>", e);
            }
        });
    }
}
